#include "client.hh"

const std::string svr_host = "127.0.0.1";
const int svr_port = 8989;

void showMenu()
{
    std::cout << "========== 通讯录客户端 ==========\n";
    std::cout << "1. 新增一个联系人\n";
    std::cout << "2. 删除一个联系人\n";
    std::cout << "3. 查看联系人列表\n";
    std::cout << "4. 查看某个联系人\n";
    std::cout << "0. 退出\n";
    std::cout << "==================================\n";
}

int main()
{
    // 构造http客户端
    httplib::Client client(svr_host, svr_port);

    int choice = 0;
    while (true)
    {
        showMenu();
        std::cin >> choice;
        std::cin.ignore(256, '\n');

        try
        {
            switch (choice)
            {
            case 1:
                addContact(client);
                break;
            case 2:
                deleteContact(client);
                break;
            case 3:
                viewContactList(client);//查看联系人列表
                break;
            case 4:
                viewContact(client);//查看某个联系人的详细信息
                break;
            case 0:
                std::cout << "退出程序。\n";
                return 0;
            default:
                std::cout << "无效选择，请输入 1-5 之间的数字。\n";
                break;
            }
        }
        catch (const ContactException& exp)
        {
            std::cerr << exp.what() << std::endl;
        }

        std::cout << "\n"; 
    }

    return 0;
}